From 8a062f4f9a1cfb2e3424d9a6e1acdbd5dd8d41be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Sun, 4 Mar 2018 17:48:36 +0100 Subject: [PATCH] gskpango: Don't create text nodes for clipped text Measure the text here directly and check if the created node bounds will be clipped away before even creating the text node. --- gtk/gskpango.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/gtk/gskpango.c b/gtk/gskpango.c index 2021e92ae8..04b58f566e 100644 --- a/gtk/gskpango.c +++ b/gtk/gskpango.c @@ -115,11 +115,43 @@ gsk_pango_renderer_show_text_glyphs (PangoRenderer *renderer, int x_offset, y_offset; GskRenderNode *node; GdkRGBA color; + graphene_rect_t node_bounds; + PangoRectangle ink_rect; + + pango_glyph_string_extents (glyphs, font, &ink_rect, NULL); + pango_extents_to_pixels (&ink_rect, NULL); + + /* Don't create empty nodes */ + if (ink_rect.width == 0 || ink_rect.height == 0) + return; gtk_snapshot_get_offset (crenderer->snapshot, &x_offset, &y_offset); + + graphene_rect_init (&node_bounds, + x_offset + (float)x/PANGO_SCALE, + y_offset + (float)y/PANGO_SCALE + ink_rect.y, + ink_rect.x + ink_rect.width, + ink_rect.height); + + /* Remove the snapshot offset from the position here again since + * gtk_snapshot_clips_rect will apply it to the given rect. */ + if (gtk_snapshot_clips_rect (crenderer->snapshot, + &(cairo_rectangle_int_t){ + node_bounds.origin.x - x_offset, + node_bounds.origin.y - y_offset, + ceil (node_bounds.size.width), + ceil (node_bounds.size.height) + })) + return; + get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color); - node = gsk_text_node_new (font, glyphs, &color, x_offset + (double)x/PANGO_SCALE, y_offset + (double)y/PANGO_SCALE); + node = gsk_text_node_new_with_bounds (font, + glyphs, + &color, + x_offset + (double)x/PANGO_SCALE, + y_offset + (double)y/PANGO_SCALE, + &node_bounds); if (node == NULL) return; -- 2.30.2